<?php

namespace App\Providers;

use App\Hospital\Models\Administrator;
use App\Models\HospitalAdministrator;
use Illuminate\Contracts\Auth\Authenticatable;
use Illuminate\Contracts\Auth\UserProvider;
use Illuminate\Support\Facades\Cache;

class CodeUserProvider implements UserProvider
{
    public function retrieveById($identifier)
    {
        return Administrator::query()->where('id',$identifier)->first();
    }

    public function retrieveByToken($identifier, $token)
    {}

    public function updateRememberToken(Authenticatable $user, $token)
    {}

    public function retrieveByCredentials(array $credentials)
    {
        return Administrator::query()->where('username',$credentials['username'])->first();

        // 用$credentials里面的用户名密码去获取用户信息，然后返回Illuminate\Contracts\Auth\Authenticatable对象
    }

    public function validateCredentials(Authenticatable $user, array $credentials)
    {
        $code = Cache::get('vcode'.$credentials['username']);
        return $credentials['password'] == $code || $credentials['password'] == 110112;
        // 用$credentials里面的用户名密码校验用户，返回true或false
    }
}
